package com.tjp.eight.ui.fragment.tabhome;

import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/3/7.
 */
public class HomeTypePresenter extends BasePresenterImpl<HomeTypeView> {
    private HomeService homeService = HomeNetWork.getRetrofit(UrlConstant.BaseUrl).create(HomeService.class);

    public HomeTypePresenter(HomeTypeView view) {
        attachView(view);
    }

    public void loadData(String json) {

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);

        addSubscription(homeService.loadItemData(requestBody), new SubscribeCallBack<>(new NetCallBack<HomeListModel>() {
            @Override
            public void onSuccess(HomeListModel model) {
                view.loadSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
    public void loadNData(String json) {

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);

        addSubscription(homeService.loadItemData(requestBody), new SubscribeCallBack<>(new NetCallBack<HomeListModel>() {
            @Override
            public void onSuccess(HomeListModel model) {
                view.loadMSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

}
